<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>物料管理</title>
	<meta name="decorator" content="default"/>
	<%@include file="/WEB-INF/views/include/treeview.jsp" %>
	<link rel="stylesheet" type="text/css"
		href="${ctxStatic}/easyui/themes/default/easyui.css">
	<link rel="stylesheet" type="text/css"
		href="${ctxStatic}/easyui/themes/icon.css">
	<link rel="stylesheet" type="text/css"
		href="${ctxStatic}/easyui/demo/demo.css">
	<script type="text/javascript" src="${ctxStatic}/easyui/jquery.min.js"></script>
	<script type="text/javascript"
		src="${ctxStatic}/easyui/jquery.easyui.min.js"></script>
	<style type="text/css">
		.ztree {overflow:auto;margin:0;_margin-top:10px;padding:10px 0 0 10px;}
	</style>
</head>
<body>
	<a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-save'" onclick="save();">新增</a>	
	<a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-edit'" onclick="edit();">编辑</a>
	
	<div id="dlg" class="easyui-dialog"  style="width:400px;height:200px;padding:10px">
			<span>物料类型编号：</span><input id="materialCode"  class='easyui-textbox'  style='width:30%;height:22px'/>
			<div></div><br>
			<span>物料类型名称：</span><input id="materialName"  class='easyui-textbox'  style='width:30%;height:22px'/><br>
	</div>
	
	<script type="text/javascript">
		var id='';//包括编号和等级
		var name='';
		var parentId='';
		$(function(){
			id='${typeId}';
			name='${typeName}';
			parentId='${parentId}';
			if(null!=parentId&&''!=parentId){
				parentId=parentId.split("-")[0];
			}
			$("#dlg").dialog('close');
		});
		
		function save(){
			//显示浮框
			$("#dlg").dialog({
				onOpen:function(){
					$("#materialCode").textbox('setValue',parentId);
				},
				title:'新增',
				buttons:[{
        			text:'修改',
					iconCls:'icon-ok',
    				handler:function(){
    					var materialCode=$("#materialCode").textbox("getValue");
    					var materialName=$("#materialName").textbox("getValue");
    					var iInvCGrade= id.split("-")[1];
    					//异步校验编号是否重复
    					$.ajax({
						    url: '${ctx}/erp/goodsType/addMaterial',         
						    data: {iInvCGrade:iInvCGrade,cInvCCode:materialCode,cInvCName:materialName,type:'1'},
						    dataType: "json",
						    type: "POST",
						    success: function (data) {
						    	if('1'==data){
						    		$.messager.alert('新增','新增完成!','info',function(){
						    			$("#dlg").dialog('close');
						    		});
						    	}else{
						    		$.messager.alert('新增','物料类型编号或名字已经存在','error');
						    	}
						    }
						});
    				}
        		},
				{
					text:'取消',
					handler:function(){
						$("#dlg").dialog('close');
					}
				}]
			});
			
		}
		function edit(){
			$("#dlg").dialog({
				onOpen:function(){
					id=id.split("-")[0]
					//打开时默认设置编号开头为父编号
					$("#materialCode").textbox('setValue',id).textbox('textbox').attr('readonly',true);
					$("#materialName").textbox('setValue',name);
				},
				title:'编辑',
				buttons:[{
        			text:'修改',
					iconCls:'icon-ok',
    				handler:function(){
    					var materialCode=$("#materialCode").textbox("getValue");
    					var materialName=$("#materialName").textbox("getValue");
    					var iInvCGrade= id.split("-")[1];
    					//异步校验编号是否重复
    					$.ajax({
						    url: '${ctx}/erp/goodsType/updateMaterial',         
						    data: {iInvCGrade:iInvCGrade,cInvCCode:materialCode,cInvCName:materialName},
						    dataType: "json",
						    type: "POST",
						    success: function (data) {
						    	if('1'==data){
						    		$.messager.alert('修改','修改完成!','info',function(){
						    			$("#dlg").dialog('close');
						    		});
						    	}else{
						    		$.messager.alert('修改','物料类型编号或名字已经存在','error');
						    	}
						    }
						});
    				}
        		},
				{
					text:'取消',
					handler:function(){
						$("#dlg").dialog('close');
					}
				}]
			});
		}
	</script>
</body>
</html>